﻿using Rabbit.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rabbit.Domain;
using Rabbit.DTO.Input;
using Rabbit.DTO.Output;

namespace Rabbit.Service
{
    public class ImagesService
    {

        RabbitRepository<Imgaes> _ires;

        public ImagesService(RabbitRepository<Imgaes> ires)
        { 
            _ires = ires; 
        }

        /// <summary>
        /// 添加图片
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public int AddImage(ImagesInput input)
        {
            var list = new Imgaes();
            list.AddDate = DateTime.Now;
            list.AddName = input.AddName;
            list.Iurl = input.Iurl;
            list.TMid = input.TMid;
            return _ires.Add(list);
        }
        /// <summary>
        /// 图片显示
        /// </summary>
        /// <param name="tmid"></param>
        /// <returns></returns>
        public List<ImagesOutput> GetImages(int tmid)
        {
            var list = new List<ImagesOutput>();
            var data=_ires.GetAll().Where(x=>x.TMid==tmid&&x.IsDel!=1).ToList();
            foreach (var image in data)
            {
                list.Add(new ImagesOutput { Iurl = image.Iurl,Iid=image.Iid }) ; 
            }

            return list;
        }
        /// <summary>
        /// 删除图片
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public int DelImage(int ids)
        {
            var list=_ires.GetAll().Where(x=>x.Iid==ids).ToList();
            foreach(var item in list)
            {
                item.IsDel = 1;
                item.DelDate = DateTime.Now;
                item.DelName = "老八";
            }
            return _ires.Update(list);
        }


    }
}
